/**
 * Copyright 2015-2016 org.lychee.com 
 * All rights reserved.
 *
 * @project
 * @author pro
 * @version 1.0
 * @date 2016-03-07
 */
package com.eyaomall.wxmall.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.eyaomall.wxmall.model.po.Address;
import com.lycheeframework.core.annotation.NameSpace;
import com.lycheeframework.core.support.DaoSupport;
/**
 * 收货地址dao
 * @author pro
 *
 */
@Repository
@NameSpace("address")
public class AddressDao extends DaoSupport<Address> {

	/**
	 * 根据ID查询收货地址
	 * @param id
	 * @return
	 */
	public Address queryById(Integer id){
		Address address = new Address();
		address.setId(id);
		
		return (Address) super.query(address);
	}
	
	/**
	 * 根据memberId查询收货地址列表
	 */
	@SuppressWarnings("unchecked")
	public List<Address> list(Integer memberId){
		Address address = new Address();
		address.setMemberId(memberId);
		return super.list(address);
	}
	
	/**
	 * 新增收货地址
	 */
	public int createAddress(Address address){
		super.insert(address);
		return address.getId();
	}
	
	/**
	 * 修改收货地址
	 */
	public boolean updateAddress(Address address){
		return super.update(address) > 0 ? true : false;
	}
	
	/**
	 * 删除收货地址
	 */
	public boolean deleteAddress(Integer id){
		Address add = new Address();
		add.setId(id);
		add.setIsDeleted("y");
		return super.update(add) > 0 ? true : false;
	}
	
	
	/**
	 * 修改为默认地址
	 */
	public boolean updateIsDefault(Integer id){
		Address add = new Address();
		add.setId(id);
		add.setIsDefault("y");
		return super.update(add) > 0 ? true : false;
	}
	
	/**
	 * 根据Member取消默认地址
	 */
	public boolean UpdateCancel(Integer memberId){
		Address add = new Address();
		add.setMemberId(memberId);
		return super.update("updateCancel",add)> 0 ? true : false;
	}
	
	
	/**
	 * 根据MemberId查询收货地址
	 */
	public Address queryByMemberId(Integer memberId){
		Address address = new Address();
		address.setMemberId(memberId);
		return (Address) super.query("queryByMemberId",address);
	}
}
